﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using Universe.MediaProbe.Utils;

namespace Universe.MediaProbe.Tests.Videos
{
    class ResMan
    {
        public static Lazy<string> VintageVideoAsFile = new Lazy<string>(() =>
        {
            string name = "Universe.mp4";
            var s = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof (ResMan), name);
            if (s == null)
                throw new InvalidOperationException("Resource " + name + " not found");

            
            string folder = SmartyTemp.GetTempFolderSmarty("Test Video Source");
            string file = Path.Combine(folder, name);
            using(s)
            using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            {
                StreamExtentions.Copy(s, fs);
            }

            SmartyTemp.KillOnRestart(file);
            SmartyTemp.KillOnRestart(folder);


            return file;

        }, LazyThreadSafetyMode.ExecutionAndPublication);
    }
}
